import request from '@/utils/request'

// 获取报警日志
export const getAlarmLog = (params: any) =>
    request({
        url: '/api/alarm/log',
        method: 'get',
        params
    })

export const getTempData = (params: any) =>
    request({
        url: '/api/data/tempdata',
         method: 'get',
        params
    })
export const getPressureData = (params: any) =>
    request({
        url: '/api/data/pressuredata',
         method: 'get',
        params
    })

export const getElecData = (params: any) =>
    request({
        url: '/api/data/elecdata',
        method: 'get',
        params
    })

export const getFlowData = (params: any) =>
    request({
        url: '/api/data/flowdata',
        method: 'get',
        params
    })

export const alarm = (params: any) =>
    request({
        url: '/api/alarm',
        method: 'get',
        params
    })
export const addAlarm = (data: any) =>
    request({
        url: '/api/alarm',
        method: 'post',
        data
    })
export const putAlarm = (data: any) =>
    request({
        url: '/api/alarm',
        method: 'put',
        data
    })
export const delAlarm = (data: any) =>
    request({
        url: `/api/alarm/${data}`,
        method: 'delete',
    })


export const exportExcel = (params: any) =>
    request({
        url: '/data/export-excel',
        method: 'get',
        params,
        responseType: undefined // 不设置 responseType
    })
export const exportExcelPressure = (params: any) =>
    request({
        url: '/data/export-excel-pressure',
        method: 'get',
        params,
        responseType: undefined // 不设置 responseType
    })

export const exportExcelElec = (params: any) =>
    request({
        url: '/data/export-excel-elec',
        method: 'get',
        params,
        responseType: undefined // 不设置 responseType
    })
export const exportExcelFlow = (params: any) =>
    request({
        url: '/data/export-excel-flow',
        method: 'get',
        params,
        responseType: undefined // 不设置 responseType
    })
// 获取所有项目
export const getAllProjects = (params: undefined) => {
    return request({
        url: '/api/projects',
        method: 'get',
        params
    });
};

// 根据ID获取项目
export const getProjectById = (id: any) => {
    return request({
        url: `/api/projects/${id}`,
        method: 'get'
    });
};

// 创建新项目
export const createProject = (data: { projectName: any; linkUrl: any }) => {
    return request({
        url: '/api/projects',
        method: 'post',
        data
    });
};

// 更新项目
export const updateProject = (id: any, data: any) => {
    return request({
        url: `/api/projects/${id}`,
        method: 'put',
        data
    });
};

// 删除项目
export const deleteProject = (id: any) => {
    return request({
        url: `/api/projects/${id}`,
        method: 'delete'
    });
};
// 发送设备命令
export const sendCommand = (data: { sn: string, command: string }) =>
    request({
        url: '/api/api-devicesCtrl/device/command',
        method: 'post',
        data
    })
// 获取设备列表
export const getDevices = () =>
    request({
        url: '/api/api-devicesCtrl/devicesCtrl',
        method: 'get'
    })

// 添加新设备
export const addDevice = (data: any) =>
    request({
        url: '/api/api-devicesCtrl/devicesCtrl',
        method: 'post',
        data
    })

// 更新设备信息
export const updateDevice = (id: number, data: any) =>
    request({
        url: `/api/api-devicesCtrl/devicesCtrl/${id}`,
        method: 'put',
        data
    })

// 删除设备
export const deleteDevice = (id: number) =>
    request({
        url: `/api/api-devicesCtrl/devicesCtrl/${id}`,
        method: 'delete'
    })